package com.atmilan.quartz.sync.pull.daigo.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.atmilan.quartz.model.entity.daigo.DaigoBrand;
import com.atmilan.quartz.sync.pull.daigo.mapper.DaigoBrandMapper;
import com.atmilan.quartz.sync.pull.daigo.service.IDaigoBrandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

@Service
public class DaigoBrandServiceImpl extends ServiceImpl<DaigoBrandMapper, DaigoBrand> implements IDaigoBrandService {

    @Autowired
    DaigoBrandMapper daigoBrandMapper;

    @Override
    public DaigoBrand getBrandByBrandId(Integer brandId) {
        return this.getOne(Wrappers.<DaigoBrand>lambdaQuery()
                .eq(DaigoBrand::getBrandId,brandId), false);
    }

    @Override
    public List<String> getAllBrandId() {
        List<Object> list = daigoBrandMapper.selectObjs(new QueryWrapper<DaigoBrand>().select("brand_id"));
        return list == null? new ArrayList<String>():list.stream().map(o->o.toString()).collect(Collectors.toList());
    }

    @Override
    public List<String> getAllBrandName() {
        List<Object> list = daigoBrandMapper.selectObjs(new QueryWrapper<DaigoBrand>().select("brand_name"));
        return list == null? new ArrayList<String>():list.stream().map(o->o.toString()).collect(Collectors.toList());
    }

    @Override
    public DaigoBrand getBrandIdByBrandName(String brandName) {
        QueryWrapper<DaigoBrand> qw = new QueryWrapper<>();
        qw.lambda().eq(DaigoBrand::getBrandName,brandName);
        DaigoBrand daigoBrand = this.getOne(qw);
        return daigoBrand;
    }
}
